package com.briup.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.demo.bean.CmsStudent;
import com.briup.demo.common.Response;
import com.briup.demo.server.CmsStudentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api(tags = "学生信息管理")
@RestController
@RequestMapping("/student")
public class CmsStudentController {

	@Autowired
	CmsStudentService studentService;

	@ApiOperation(value="更新或保存学生信息")
	@PostMapping("/saveOrUpdate")
	public Response<String> savaOrUpdate(CmsStudent c){
		studentService.saveOrUpdate(c);
		return Response.ok("操作成功！");
	}
	
	@ApiOperation(value = "按照学生学号删除信息")
	@ApiImplicitParam(name = "num",value = "学生学号",required = true)
	@DeleteMapping("/deleteByNum")
	public Response<String> deleteById(String num){
		int count = studentService.deleteByNum(num);
		return Response.ok("删除成功"+count+"条栏目！");
	}
	
	@DeleteMapping("/deleteByNums")
	public Response<String> deleteByIds(String[] nums){
		int count = studentService.batchDelete(nums);
		return Response.ok("删除成功"+count+"条栏目！");
	}
	@GetMapping("/all")
	public Response<List<CmsStudent>> findAll(){
		List<CmsStudent> all = studentService.findAll();
		return Response.ok(all) ;
	}
	//
	@GetMapping("/findByName")
	public Response<List<CmsStudent>> findByName(String name){
		List<CmsStudent> student = studentService.findByName(name);
		return Response.ok(student);
	}

}
